package com.example.day3.exercise;

import java.util.stream.Stream;

/**
 * 将 filter 的课堂例题修改为方法引用方式实现
 */
public class Exercise1 {
    public static void main(String[] args) {
        Stream.of(
                        new Fruit("草莓", "Strawberry", "浆果", "红色"),
                        new Fruit("桑葚", "Mulberry", "浆果", "紫色"),
                        new Fruit("杨梅", "Waxberry", "浆果", "红色"),
                        new Fruit("核桃", "Walnut", "坚果", "棕色"),
                        new Fruit("草莓", "Peanut", "坚果", "棕色"),
                        new Fruit("蓝莓", "Blueberry", "浆果", "蓝色")
                )
                .filter(Fruit::isBerry)
                .filter(Fruit::isBlue)
                .forEach(System.out::println);
    }

    record Fruit(String cname, String name, String category, String color) {
        // 判断是否是浆果
        public boolean isBerry() {
            return "浆果".equals(category);
        }

        // 判断是否是蓝色
        public boolean isBlue() {
            return "蓝色".equals(color);
        }
    }
}
